#!/bin/bash -e

function info() {
echo Usage: `basename $0` [-m] in.bam
echo delete dup default, -m to mark
exit 65
}

while getopts  ":mp:" opts
do
        case  $opts  in
        m)
			markdup=true
			;;
		p)
			out_prefix=$OPTARG
			;;
		\?) info;;
        esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------


if test "$markdup" = "true"
then
	
	echo;echo;echo picard MarkDuplicates mark
	java $tmp -jar ${tools_path}/picard-tools-1.119/MarkDuplicates.jar \
	I=$1 \
	O=$out_prefix.markdup.bam \
	METRICS_FILE=$out_prefix.markdup.metrics.txt \
	PROGRAM_RECORD_ID=dup \
	PROGRAM_GROUP_NAME=dup \
	CREATE_INDEX=true
else
	echo;echo;echo picard MarkDuplicates delete
	java $tmp -jar ${tools_path}/picard-tools-1.119/MarkDuplicates.jar \
	I=$1 \
	O=$out_prefix.deldup.bam \
	METRICS_FILE=$out_prefix.deldup.metrics.txt \
	PROGRAM_RECORD_ID=dup \
	PROGRAM_GROUP_NAME=dup \
	REMOVE_DUPLICATES=true \
	CREATE_INDEX=true
fi

cat $out_prefix.*dup.metrics.txt|grep -v '^#'|tab2xls.pl - $out_prefix.dup.xls

. $cmd_done